/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Administrator
*/
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;

public class java2DThread extends JFrame {

	final static int WIDTH = 600;
	final static int HEIGHT = 600;

	public java2DThread() {
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int w = screenSize.width;
		int h = screenSize.height;
		int x = (w - WIDTH) / 2;
		int y = (h - HEIGHT) / 2;
		this.setLocation(x, y);
		this.setSize(WIDTH, HEIGHT);
		this.setTitle("java 2D 示例");
	}

	public void paint(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		BasicStroke stroke = new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
		g2.setStroke(stroke);
		g.drawRect(10, 50, 100, 100);//画矩形
		g.fillRect(120, 50, 100, 100);//画填充矩形
		g.drawLine(230, 50, 330, 150);//画直线
		g.drawRoundRect(340, 50, 100, 100, 10, 10);//画圆角矩形
		g.fillRoundRect(450, 50, 100, 100, 10, 10);//画填充的圆角矩形
		g.setColor(Color.green);
		g.drawLine(0, 155, 600, 155);//绘制分割线
		g.setColor(Color.lightGray);
		g.draw3DRect(10, 160, 100, 100, true);//画3D矩形，凸出
		g.draw3DRect(120, 160, 100, 100, false);//凹下
		g.drawOval(230, 160, 100, 100);//画半径为100的圆
		g.fillOval(340, 160, 100, 100);//画填充的半径为100的圆
		g.drawOval(450, 160, 100, 50);//在（450，160）处绘制长轴为100，短轴为50的椭圆
		g.drawLine(0, 265, 600, 265);//绘制分割线
		//g.drawArc(10,170,100,100,0,90);
		//g.drawArc(120,170,100,100,0,-90);
		//文本绘制
		Font f1 = new Font("TimesRoman", Font.ITALIC, 30);
		Font f2 = new Font("TimesRoman", Font.BOLD, 30);
		g.setFont(f1);
		g.setColor(Color.red);
		g.drawString("This is a italic font", 20, 300);
		g.setFont(f2);
		g.setColor(Color.blue);
		g.drawString("This is a bold font", 20, 325);
		g.setColor(Color.GREEN);
		g.drawLine(0, 375, 600, 375);
		//简单图像绘制

		try {
			File img_file = new File(
					"F:\\my_program\\MYJAVA\\wstjava\\ThreadTest\\build\\classes\\com\\thread\\rescue.JPG");
			Image src = ImageIO.read(img_file);
			int img_width = src.getWidth(null);
			int img_height = src.getHeight(null);
			BufferedImage img = new BufferedImage(img_width, img_height, BufferedImage.TYPE_INT_RGB);
			g.drawImage(img, 50, 400, 200, 100, null);
		} catch (IOException e) {
			e.printStackTrace();
		}

		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public static void main(String[] args) {
		java2DThread test = new java2DThread();
		test.setVisible(true);
	}
}
